<?php
require_once dirname(__FILE__) . '/../incls/php/config.php';
require_once dirname(__FILE__) . '/../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../incls/php/dbutils.class.php';
session_name(SESSION);
session_start();
$logout = MiscUtils::getParam('logout', NULL);
$url = MiscUtils::getParam('url', NULL);
$menu = MiscUtils::getParam('menu', NULL);
$mod = MiscUtils::getParam('mod', 'login');
if ($logout) {
  unset($_SESSION[ADMIN]);
  header('location: http://' . URL . 'instls.php');
  return;
}
if ($mod != 'login' && !isset($_SESSION[ADMIN])) {
  $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  header('location: http://' . URL . 'instls.php?url=' . urlencode($url));
  return;
} else if ($mod == 'login' && isset($_SESSION[ADMIN])) {
  if (!$url) {
    $url = 'http://' . URL . 'instls.php?mod=systems&menu=systems';
  }
  header('location: ' . $url);
  return;
}
?>
<html>
<head>
<title>PZ</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
  outline: 0;
  margin: 0;
}
body {
  background-image: url(instls/assets/imgs/bg.png);
  background-repeat: repeat;
}
.superscript {
  background-color: #653D3D;
  border-bottom: 1px solid #ddd;
  text-align: center;
}
.menubar td.menu {
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  background-color: #825050;
  min-width: 80px;
  border: 1px solid #825050;
  border-bottom: 0;
  height: 25px;
}
.menubar td.menu a {
  background-image: none !important;
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0;
  font-weight: bold;
}
.hi {
  background-color: #D9D6CD !important;
  border: 1px solid #D9D6CD;
  font-weight: bold;
}
.hi a {
  color: #825050 !important;
}
.right {
  text-align: center;
  vertical-align: middle;
  border-bottom: 0;
  font-size: 14px;
  font-family: Trebuchet MS;
  font-weight: bold;
}
.admin {
  background-color: #fed6c2;
  border: 1px solid #fed6c2;
  width: 60px;
}
.logout {
  background-color: #2bcb06;
  border: 1px solid #2bcb06;
  width: 80px;
}
.logout a {
  color: #fff;
  font-size: 14px;
  font-family: Lucida Sans Unicode;
  font-weight: bold;
  text-decoration: none;
}
.nav {
  height: 25px;
}
.nav a {
  color: #000; 
  font-weight: bold; 
  font-size: 14px;
}
.arrow {
  width: 20px;
  text-align: center;
  color: #aaa;
}
.image_button {
  background-color: #fff;
  border-bottom: 2px solid #666666;
  border-right: 2px solid #666666;
  border-top: 1px solid #bbbbbb;
  border-left: 1px solid #bbbbbb;
  font-weight: bold;
  cursor: pointer;
  display: inline-block;
  width: 60px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  vertical-align: middle;
  color: #000;
}
</style>

</head>
<body>
<div class="superscript">
  <table style="width: 100%;" cellPadding=0 cellSpacing=0>
    <tr>
      <td style="width: 130px;"><img src="<?php echo "instls/assets/imgs/logo.png"?>"></img></td>
      <td style="padding-left: 20px; vertical-align: bottom;">
        <?php if ($mod != 'login') { ?>
        <table class="menubar" cellPadding=0 cellSpacing=0>
          <tr>
            <td class="menu <?php if ($menu == 'systems') echo ' hi'; ?>" onclick="location.href='?mod=systems&menu=systems'"><a href="?mod=systems&menu=systems">Systems</a></td>
            <td style="width: 2px;"></td>
            <td class="menu <?php if ($menu == 'plugins') echo ' hi'; ?>" onclick="location.href='?mod=plugins&menu=plugins'"><a href="?mod=plugins&menu=plugins">Plugins</a></td>
            <td style="width: 2px;"></td>
            <td class="menu <?php if ($menu == 'uis') echo ' hi'; ?>" onclick="location.href='?mod=uis&menu=uis'"><a href="?mod=uis&menu=uis">Themes</a></td>
            <td style="width: 2px;"></td>
            <td class="menu <?php if ($menu == 'profile') echo ' hi'; ?>" onclick="location.href='?mod=profile&menu=profile'"><a href="?mod=profile&menu=profile">Profile</a></td>
          </tr>
        </table>
        <?php } ?>
      </td>
      <td style="text-align: right; vertical-align: bottom;">
        <?php if ($mod != 'login') { ?>
        <table style="margin-left: auto;" cellpadding="0" cellspacing="0">
          <tr>
            <td class="right admin">Admin</td>
            <td class="right logout" onclick="location.href='?logout=1'"><a href="?logout=1">Logout</a></td>
          </tr>
        </table>
        <?php } ?>
      </td>
    </tr>
  </table>
</div>
<div style="padding-left: 10px;">
<div id="nav" style="height: 10px;">&nbsp;</div>
<?php include dirname(__FILE__) . '/mods/' . $mod . '/index.php'; ?>
</div>
<script type="text/javascript">
  function nav(entries) {
    var table, tr, td, elm;
    elm = document.getElementById('nav');
    elm.style.height = '';
    elm.style.paddingBottom = '15px';
    while (elm.firstChild) {
      elm.removeChild(elm.firstChild);
    }
    table = document.createElement('table');
    elm.appendChild(table);
    tr = table.insertRow(-1);
    for (var idx in entries) {
      var obj = entries[idx];
      td = tr.insertCell(-1);
      td.className = 'nav';
      if (obj.href == '') {
        td.appendChild(document.createTextNode(obj.name));
      } else {
        elm = document.createElement('a');
        elm.href = obj.href;
        elm.appendChild(document.createTextNode(obj.name));
        td.appendChild(elm);
      }
      if (idx != entries.length - 1) {
        td = tr.insertCell(-1);
        td.className = 'arrow';
        td.appendChild(document.createTextNode('>'));
      }
    }
  };
</script>
</body>
</html>